Improve completion popup menu
Vim 7's popup menu for completion (omni or otherwise) takes a little getting used to when it comes to selecting the completed word. See . The completed word can be selected using the arrow, PgUp/PgDn, Enter and Esc keys. In addition to that, there is Ctrl-E, Ctrl-Y, Ctrl-N and Ctrl-P. Here's an alternative setup that feels a little more like the completion menu of other IDEs inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\\\" : "\" inoremap pumvisible() ? "\\\" : "\" Use the Up/Down arrow and PgUp/PgDn keys to scroll through the popup menu. The word in text will change as you scroll through. Press Enter to accept the selected word. Hit Esc to cancel completion and go back to the original word. Those who prefer Esc to work like Enter can use this inoremap =pumvisible() ? "\" : "\" Word to the wise, mapping over can cause an issue in terminal vim where arrow keys will print letters A through D along with a newline rather than moving. To avoid the issue, simply omit the mapping over . For scrolling using PgUp/PgDn, one can also map Ctrl-u and Ctrl-d to PgUp and PgDn respectively inoremap pumvisible() ? "\\\" : "\" inoremap pumvisible() ? "\\\" : "\" The following option inserts only the longest common text of the matches. set completeopt+=longest Comments :Fixed mappings. Replaced original mappings with the mappings in the comments. Merged the comments with the tip, and removed some that didn't belong. :I think the name of this tip should be changed to something more suitable. :--Spiiph 14:41, 18 January 2009 (UTC) ::Thanks. Any suggestions for a better title? Do you not like "Improve"? --JohnBeckett 02:51, 19 January 2009 (UTC) :I actually like the behavior of and but using and is more convenient, so prefer to map to etc. rather than the other way. However, for some reason, imaps on and get ignored when omni-completion popup is visible (but work fine for other completion popups). I asked a question about this long back in vim (e.g., see http://markmail.org/thread/rz6bpanuwneavfym) and didn't get a conclusive response. Anyone knows how to workaround this issue? :--Haridsv 01:34, 12 March 2009 (UTC) ::Mappings only work in the generic 'complete' completion (/), not in any completion that is started with . This seems to be a design decision. Cp. the notes below . ::To work around this (apart from patching Vim itself), you would need to break out of mode. The only way I can think of (and I haven't tried this), is to append a =MyInterceptor() mapping behind every mapping that can enter completion mode (i.e. all mappings: inoremap =MyInterceptor()). Inside the MyInterceptor() function, use and to query the completion key from the user. Then, you'll be able to translate to , etc., and return any other keys unfiltered. ::I was thinking of defaulting to instead of , too, but then stuck with the default mappings, which are useful, too. (And the auto-insertion of matches sometimes saves one from explicitly acknowledging the match, thus saving one keystroke.) -- Inkarkat 13:31, 16 June 2009 (UTC) :I had some issues with the mapping given here, and some github bugs back up the idea that it is not uncommon, so I added a caveat about it to the article. 18:15, May 2, 2013 (UTC) ----